<?php defined('SYSPATH') or die('No direct script access.');

abstract class Controller_Index_Base extends Controller
{
    protected $title  = 'PromoTnx';
    protected $layout = 'index/layout_tpl';
    
    public function before()
    {
        parent::before(); 
        $this->_get_subid();   
    }
    
    protected function _get_subid()
    {
        if (isset($_GET['subid']) && ($subid = $_GET['subid'])) {
            setcookie('subid', $subid, time()+30*24*60*60, '/');     // 30 дней 
            
            $url = $_SERVER['REQUEST_URI'];
            $url = str_replace(array('?subid='.$subid, '&subid='.$subid), array('', ''), $url);
            header('Location: '.$url);
            die();   
        }
    }
    
    public function print_template($title, $content, $description = null, $page_head = null)
    {
        $this->layout = new View($this->layout);

        $this->layout->title       = $title.' - '.$this->title;
        $this->layout->content     = $content;
        $this->layout->description = $description;
        $this->layout->page_head   = $page_head;
        
        $this->response->body($this->layout);
    }

}
